import { fileURLToPath, URL } from 'node:url'

import { defineConfig,loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'

import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

import Icons from 'unplugin-icons/vite'
import IconsResolver from 'unplugin-icons/resolver'
// https://vitejs.dev/config/
export default defineConfig({
  server:{
    proxy:{
      // 下面这个代码的意思是当需要向第二个
      '/front':{
        // 下面这句意思是寻找env文件在哪，这个文件现在建立在src文件夹下
        target:loadEnv("",process.cwd()).VITE_API_URL,
        //下面这句代码意思是 B代理服务器知道这个请求是A服务器发起的
        changeOrigin:true,
      },
      // 当你访问后端接口时
      'boss/':{
        target:loadEnv("",process.cwd()).VITE_API_URL,
        changeOrigin:true
      }

    }
  },
  plugins: [
    vue(),
    AutoImport({
      imports: ['vue'],
      resolvers: [ElementPlusResolver(), IconsResolver({})],
      eslintrc: { enabled: true }
    }),
    Components({
      resolvers: [
        ElementPlusResolver(),
        IconsResolver({
          enabledCollections: ['ep']
        })
      ]
    }),
    Icons({
      autoInstall: true
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  }
})
